*** This File Takes Raw PSID Data and Produces the Results from all Tables and Figure 3 in "DO FAMILY WEALTH SHOCKS AFFECT FERTILITY CHOICES?
*** EVIDENCE FROM THE HOUSING MARKET"

* This File is meant to run on Stata 10 and uses the stata add-on package "dmerge".*

clear
set mem 1000m
set matsize 1000
set more off

* Read in Raw PSID Data - These data contain only public access variables *

use indfamcah90_1
gen year=90
save psid-fertility, replace

local t "91 92 93 94 95 96 97 99 01 03 05"
foreach x of local t{
use indfamcah`x'_1
gen year=`x'
append using psid-fertility
save psid-fertility, replace
}

do psid2007-setup
append using psid-fertility

* Fix Years *

replace year=year+1900
replace year=year+100 if year<1990

* Generate Household IDs *

gen id=hohin90 if year==1990
replace id=hohin91 if year==1991
replace id=hohin92 if year==1992
replace id=hohin93 if year==1993
replace id=hohin94 if year==1994
replace id=hohin95 if year==1995
replace id=hohin96 if year==1996
replace id=hohin97 if year==1997
replace id=hohin99 if year==1999 
replace id=hohin01 if year==2001 
replace id=hohin03 if year==2003 
replace id=hohin05 if year==2005 
replace id=hohin07 if year==2007

* Read in State Ids - These come from the restricted-access data and thus are not provided with this code. *

dmerge id year using psid-stateid
drop if _merge==2
drop _merge
replace stfips=fips07 if year==2007

* Generate Indicator for Whether Gave Birth in the Past Year *

gen birth=1 if births_1990>0 & births_1990~=. & year==1990
replace birth=1 if births_1991>0 & births_1991~=. & year==1991
replace birth=1 if births_1992>0 & births_1992~=. & year==1992
replace birth=1 if births_1993>0 & births_1993~=. & year==1993
replace birth=1 if births_1994>0 & births_1994~=. & year==1994
replace birth=1 if births_1995>0 & births_1995~=. & year==1995
replace birth=1 if births_1996>0 & births_1996~=. & year==1996
replace birth=1 if births_1997>0 & births_1997~=. & year==1997
replace birth=1 if births_1999>0 & births_1999~=. & year==1999
replace birth=1 if births_2001>0 & births_2001~=. & year==2001
replace birth=1 if births_2003>0 & births_2003~=. & year==2003
replace birth=1 if births_2005>0 & births_2005~=. & year==2005
replace birth=0 if birth==.

* Educational Attainment Indicators *

gen nohs=1 if educ<12 & educ~=.
replace nohs=0 if nohs==.
gen hsdip=educ==12
gen somecoll=1 if educ>12 & educ<16 & educ~=.
replace somecoll=0 if somecoll==.
gen ba=1 if educ==16 | educ==17
replace ba=0 if ba==.
gen edmiss=1 if educ==. | educ==98
replace edmiss=0 if edmiss==.

* Female Household Head Age *

replace age=age90 if year==1990
gen agesq=age*age

replace age1519=1 if age>=15 & age<=19 & year==2007
replace age1519=0 if age1519==. & year==2007
replace age2024=1 if age>=20 & age<=24 & year==2007
replace age2024=0 if age2024==. & year==2007
replace age2529=1 if age>=25 & age<=29 & year==2007
replace age2529=0 if age2529==. & year==2007
replace age3034=1 if age>=30 & age<=34 & year==2007
replace age3034=0 if age3034==. & year==2007
replace age3539=1 if age>=35 & age<=39 & year==2007
replace age3539=0 if age3539==. & year==2007
replace age4044=1 if age>=40 & age<=44 & year==2007
replace age4044=0 if age4044==. & year==2007

* Home Ownership Dummy *

gen ownhome=housevalue_lag0~=0
replace ownhome=0 if housevalue_lag0==.

* Create Home Price Change Variables *

gen cpi=215.303/130.7 if year==1990
replace cpi=215.303/136.1 if year==1991
replace cpi=215.303/140.3 if year==1992
replace cpi=215.303/144.5 if year==1993
replace cpi=215.303/148.2 if year==1994
replace cpi=215.303/152.4 if year==1995
replace cpi=215.303/156.9 if year==1996
replace cpi=215.303/160.5 if year==1997
replace cpi=215.303/166.6 if year==1999
replace cpi=215.303/177.1 if year==2001
replace cpi=215.303/184 if year==2003
replace cpi=215.303/195.3 if year==2005
replace cpi=215.303/207.35 if year==2007

replace housevalue_lag0=0 if housevalue_lag0==9999998 | housevalue_lag0==9999999
replace housevalue_lag2=0 if housevalue_lag2==9999998 | housevalue_lag2==9999999
replace housevalue_lag4=0 if housevalue_lag4==9999998 | housevalue_lag4==9999999

gen rhomeval=cpi*housevalue_lag0/10000

gen equity_lag0=housevalue_lag0-remmortprin_lag0
replace equity_lag0=. if remmortprin_lag0>9900000
replace equity_lag0=. if remmortprin_lag0==999999 | remmortprin_lag0==999998
replace equity_lag0=0 if ownhome==0

gen requity=equity_lag0*cpi/10000

gen rhvaldiff_2=(housevalue_lag0-housevalue_lag2)*cpi
replace rhvaldiff_2=0 if ownhome==0

gen rhvaldiff_4=(housevalue_lag0-housevalue_lag4)*cpi
replace rhvaldiff_4=0 if ownhome==0

replace rhvaldiff_2=rhvaldiff_2/10000
replace rhvaldiff_4=rhvaldiff_4/10000

gen equity_lag2=housevalue_lag2-remmortprin_lag2
replace equity_lag2=0 if housevalue_lag2==0
replace equity_lag2=. if remmortprin_lag2>9900000
replace equity_lag2=. if remmortprin_lag2==999999 | remmortprin_lag2==999998
replace equity_lag2=0 if ownhome==0

gen equity_lag4=housevalue_lag4-remmortprin_lag4
replace equity_lag4=0 if housevalue_lag4==0
replace equity_lag4=. if remmortprin_lag4>9900000
replace equity_lag4=. if remmortprin_lag4==999999 | remmortprin_lag4==999998
replace equity_lag4=0 if ownhome==0

gen requitydiff_2=(equity_lag0-equity_lag2)*cpi
replace requitydiff_2=0 if ownhome==0
replace requitydiff_2=equity_lag0*cpi if ownhome==1 & housevalue_lag2==0

gen requitydiff_4=(equity_lag0-equity_lag4)*cpi
replace requitydiff_4=0 if ownhome==0
replace requitydiff_4=equity_lag0*cpi if ownhome==1 & housevalue_lag4==0

replace requitydiff_2=requitydiff_2/10000
replace requitydiff_4=requitydiff_4/10000

* Family Income *

gen rtot_fam_y_lag0=(cpi*tot_fam_y_lag0)/10000
gen rtot_fam_y_lag2=(cpi*tot_fam_y_lag2)/10000
gen rtot_fam_y_lag4=(cpi*tot_fam_y_lag4)/10000

gen decade_90s=year<=1999
gen decade_2000s=year>=2001

drop if stfips==.
gen asample=1 if rhvaldiff_2~=. & rhvaldiff_4~=. 
sort hohin90
gen yr=year
save psid-fertility, replace

** READ IN RESTRICTED GEOCODE DATA - FILES ARE NOT PROVIDED. THE psid-geocode.dta FILE IS THE RAW PSID FILE WITH THE GEOCODES BY YEAR AND FAMILY ID **

use psid-geocode
keep YEAR FAMID FIPSTATE MSA00 TRACT00
ren FAMID hohin90
ren YEAR year
sort hohin90
keep if year==1990
merge hohin90 using psid-fertility
tab _merge if yr==1990
drop if _merge==1
gen geomerge=_merge if yr==1990
drop _merge
gen fips_state=FIPSTATE if yr==1990
gen msa=MSA00 if yr==1990
gen centract=TRACT00 if yr==1990
drop FIPSTATE FIPSTATE TRACT00
sort hohin91
save psid-fertility, replace

use psid-geocode
keep YEAR FAMID FIPSTATE MSA00 TRACT00
ren FAMID hohin91
ren YEAR year
sort hohin91
keep if year==1991
merge hohin91 using psid-fertility
tab _merge if yr==1991
drop if _merge==1
replace geomerge=_merge if yr==1991
drop _merge
replace fips_state=FIPSTATE if yr==1991
replace msa=MSA00 if yr==1991
replace centract=TRACT00 if yr==1991
drop FIPSTATE FIPSTATE TRACT00
sort hohin92
save psid-fertility, replace

use psid-geocode
keep YEAR FAMID FIPSTATE MSA00 TRACT00
ren FAMID hohin92
ren YEAR year
sort hohin92
keep if year==1992
merge hohin92 using psid-fertility
tab _merge if yr==1992
drop if _merge==1
replace geomerge=_merge if yr==1992
drop _merge
replace fips_state=FIPSTATE if yr==1992
replace msa=MSA00 if yr==1992
replace centract=TRACT00 if yr==1992
drop FIPSTATE FIPSTATE TRACT00
sort hohin93
save psid-fertility, replace

use psid-geocode
keep YEAR FAMID FIPSTATE MSA00 TRACT00
ren FAMID hohin93
ren YEAR year
sort hohin93
keep if year==1993
merge hohin93 using psid-fertility
tab _merge if yr==1993
drop if _merge==1
replace geomerge=_merge if yr==1993
drop _merge
replace fips_state=FIPSTATE if yr==1993
replace msa=MSA00 if yr==1993
replace centract=TRACT00 if yr==1993
drop FIPSTATE FIPSTATE TRACT00
sort hohin94
save psid-fertility, replace

use psid-geocode
keep YEAR FAMID FIPSTATE MSA00 TRACT00
ren FAMID hohin94
ren YEAR year
sort hohin94
keep if year==1994
merge hohin94 using psid-fertility
tab _merge if yr==1994
replace geomerge=_merge if yr==1994
drop if _merge==1
drop _merge
replace fips_state=FIPSTATE if yr==1994
replace msa=MSA00 if yr==1994
replace centract=TRACT00 if yr==1994
drop FIPSTATE FIPSTATE TRACT00
sort hohin95
save psid-fertility, replace

use psid-geocode
keep YEAR FAMID FIPSTATE MSA00 TRACT00
ren FAMID hohin95
ren YEAR year
sort hohin95
keep if year==1995
merge hohin95 using psid-fertility
tab _merge if yr==1995
replace geomerge=_merge if yr==1995
drop if _merge==1
drop _merge
replace fips_state=FIPSTATE if yr==1995
replace msa=MSA00 if yr==1995
replace centract=TRACT00 if yr==1995
drop FIPSTATE FIPSTATE TRACT00
sort hohin96
save psid-fertility, replace

use psid-geocode
keep YEAR FAMID FIPSTATE MSA00 TRACT00
ren FAMID hohin96
ren YEAR year
sort hohin96
keep if year==1996
merge hohin96 using psid-fertility
tab _merge if yr==1996
replace geomerge=_merge if yr==1996
drop if _merge==1
drop _merge
replace fips_state=FIPSTATE if yr==1996
replace msa=MSA00 if yr==1996
replace centract=TRACT00 if yr==1996
drop FIPSTATE FIPSTATE TRACT00
sort hohin97
save psid-fertility, replace

use psid-geocode
keep YEAR FAMID FIPSTATE MSA00 TRACT00
ren FAMID hohin97
ren YEAR year
sort hohin97
keep if year==1997
merge hohin97 using psid-fertility
tab _merge if yr==1997
replace geomerge=_merge if yr==1997
drop if _merge==1
drop _merge
replace fips_state=FIPSTATE if yr==1997
replace msa=MSA00 if yr==1997
replace centract=TRACT00 if yr==1997
drop FIPSTATE FIPSTATE TRACT00
sort hohin99
save psid-fertility, replace

use psid-geocode
keep YEAR FAMID FIPSTATE MSA00 TRACT00
ren FAMID hohin99
ren YEAR year
sort hohin99
keep if year==1999
merge hohin99 using psid-fertility
tab _merge if yr==1999
replace geomerge=_merge if yr==1999
drop if _merge==1
drop _merge
replace fips_state=FIPSTATE if yr==1999
replace msa=MSA00 if yr==1999
replace centract=TRACT00 if yr==1999
drop FIPSTATE FIPSTATE TRACT00
sort hohin01
save psid-fertility, replace

use psid-geocode
keep YEAR FAMID FIPSTATE MSA00 TRACT00
ren FAMID hohin01
ren YEAR year
sort hohin01
keep if year==2001
merge hohin01 using psid-fertility
tab _merge if yr==2001
replace geomerge=_merge if yr==2001
drop if _merge==1
drop _merge
replace fips_state=FIPSTATE if yr==2001
replace msa=MSA00 if yr==2001
replace centract=TRACT00 if yr==2001
drop FIPSTATE FIPSTATE TRACT00
sort hohin03
save psid-fertility, replace

use psid-geocode
keep YEAR FAMID FIPSTATE MSA00 TRACT00
ren FAMID hohin03
ren YEAR year
sort hohin03
keep if year==2003
merge hohin03 using psid-fertility
tab _merge if yr==2003
replace geomerge=_merge if yr==2003
drop if _merge==1
drop _merge
replace fips_state=FIPSTATE if yr==2003
replace msa=MSA00 if yr==2003
replace centract=TRACT00 if yr==2003
drop FIPSTATE FIPSTATE TRACT00
sort hohin05
save psid-fertility, replace

use psid-geocode
keep YEAR FAMID FIPSTATE MSA00 TRACT00
ren FAMID hohin05
ren YEAR year
sort hohin05
keep if year==2005
merge hohin05 using psid-fertility
tab _merge if yr==2005
replace geomerge=_merge if yr==2005
drop if _merge==1
drop _merge
replace fips_state=FIPSTATE if yr==2005
replace msa=MSA00 if yr==2005
replace centract=TRACT00 if yr==2005
drop FIPSTATE FIPSTATE TRACT00
sort hohin07
save psid-fertility, replace

use psid-geocode
keep YEAR FAMID FIPSTATE MSA00 TRACT00
ren FAMID hohin07
ren YEAR year
sort hohin07
keep if year==2007
merge hohin07 using psid-fertility
tab _merge if yr==2007
replace geomerge=_merge if yr==2007
drop if _merge==1
drop _merge
replace fips_state=FIPSTATE if yr==2007
replace msa=MSA00 if yr==2007
replace centract=TRACT00 if yr==2007
drop FIPSTATE FIPSTATE TRACT00
save psid-fertility, replace

drop year
ren yr year
drop geomerge
sort msa
save psid-fertility, replace

** SET UP 1980s DATA - FORMAT FOLLOWS FORMAT ABOVE ** 

do psid-80s
append using psid-fertility
save psid-fertility, replace

* Read in MSA-level home price data. This file contains the CMHPI index by MSA for years 1986-2007 *

use msa, replace
ren msafp msa
drop state pop1990 pop2000 pop2005
sort msa 
dmerge msa using psid-fertility
tab _merge
drop if _merge==1
drop _merge

* Generate State-year-level Means of Home Values and Home Price Changes *

drop if rhomeval<=.1 & ownhome==1
replace rhomeval=. if rhomeval<=.1
save psid-fertility, replace

collapse (mean) rhomeval, by(year stfips)
rename rhomeval housingprice
label var housingprice "state average home price"
xtset stfips year
gen housingpricediff_2 = housingprice - l2.housingprice
gen housingpricediff_4 = housingprice - l4.housingprice
sort year stfips
save homeprice, replace

clear
use psid-fertility
sort year stfips
merge year stfips using homeprice
drop _merge
save psid-fertility, replace

* Generate MSA-year-level Means of Home Values and Home Price Changes

replace asample=0 if tot_fam_y_lag0==9999999 & tot_fam_y_lag0~=.
replace asample=0 if tot_fam_y_lag0<-100000 & tot_fam_y_lag0~=.
replace asample=0 if (rhvaldiff_2<-30 | rhvaldiff_2>50) & rhvaldiff_2~=.
replace asample=0 if (rhvaldiff_4<-30 | rhvaldiff_4>150) & rhvaldiff_4~=.
replace asample=0 if (rhvaldiff_2<-30 | rhvaldiff_2>50) & rhvaldiff_2~=.
collapse (mean) rhomeval if asample==1 & age>24, by(year msa)
rename rhomeval housingprice_msa
label var housingprice_msa "MSA average home price"
xtset msa year
gen housingpricemsadiff_2 = housingprice_msa - l2.housingprice_msa
gen housingpricemsadiff_4 = housingprice_msa - l4.housingprice_msa
sort year msa
save homeprice_msa, replace

clear
use psid-fertility
sort year msa
merge year msa using homeprice_msa
drop _merge

* Generate Lagged Homeownership *

gen ownhome_2=housevalue_lag2~=0
replace ownhome_2=0 if housevalue_lag2==.

gen ownhome_4=housevalue_lag4~=0
replace ownhome_4=0 if housevalue_lag4==.

* Generate Predicted MSA-level Housing Price Change

gen pctcmhpidiff4=cmhpi1985/cmhpi1981 if year==1985
replace pctcmhpidiff4=cmhpi1986/cmhpi1982 if year==1986
replace pctcmhpidiff4=cmhpi1987/cmhpi1983 if year==1987
replace pctcmhpidiff4=cmhpi1988/cmhpi1984 if year==1988
replace pctcmhpidiff4=cmhpi1989/cmhpi1985 if year==1989
replace pctcmhpidiff4=cmhpi1990/cmhpi1986 if year==1990
replace pctcmhpidiff4=cmhpi1991/cmhpi1987 if year==1991
replace pctcmhpidiff4=cmhpi1992/cmhpi1988 if year==1992
replace pctcmhpidiff4=cmhpi1993/cmhpi1989 if year==1993
replace pctcmhpidiff4=cmhpi1994/cmhpi1990 if year==1994
replace pctcmhpidiff4=cmhpi1995/cmhpi1991 if year==1995
replace pctcmhpidiff4=cmhpi1996/cmhpi1992 if year==1996
replace pctcmhpidiff4=cmhpi1997/cmhpi1993 if year==1997
replace pctcmhpidiff4=cmhpi1999/cmhpi1995 if year==1999
replace pctcmhpidiff4=cmhpi2001/cmhpi1997 if year==2001
replace pctcmhpidiff4=cmhpi2003/cmhpi1999 if year==2003
replace pctcmhpidiff4=cmhpi2005/cmhpi2001 if year==2005
replace pctcmhpidiff4=cmhpi2007/cmhpi2003 if year==2007

gen pctcmhpidiff2=cmhpi1985/cmhpi1983 if year==1985
replace pctcmhpidiff2=cmhpi1986/cmhpi1984 if year==1986
replace pctcmhpidiff2=cmhpi1987/cmhpi1985 if year==1987
replace pctcmhpidiff2=cmhpi1988/cmhpi1986 if year==1988
replace pctcmhpidiff2=cmhpi1989/cmhpi1987 if year==1989
replace pctcmhpidiff2=cmhpi1990/cmhpi1988 if year==1990
replace pctcmhpidiff2=cmhpi1991/cmhpi1988 if year==1991
replace pctcmhpidiff2=cmhpi1992/cmhpi1990 if year==1992
replace pctcmhpidiff2=cmhpi1993/cmhpi1991 if year==1993
replace pctcmhpidiff2=cmhpi1994/cmhpi1992 if year==1994
replace pctcmhpidiff2=cmhpi1995/cmhpi1993 if year==1995
replace pctcmhpidiff2=cmhpi1996/cmhpi1994 if year==1996
replace pctcmhpidiff2=cmhpi1997/cmhpi1995 if year==1997
replace pctcmhpidiff2=cmhpi1999/cmhpi1997 if year==1999
replace pctcmhpidiff2=cmhpi2001/cmhpi1999 if year==2001
replace pctcmhpidiff2=cmhpi2003/cmhpi2001 if year==2003
replace pctcmhpidiff2=cmhpi2005/cmhpi2003 if year==2005
replace pctcmhpidiff2=cmhpi2007/cmhpi2005 if year==2007

gen cmhpi=cmhpi1985 if year==1985
forval x=1986(1)2007{
replace cmhpi=cmhpi`x' if year==`x'
}

gen predicted_pdiff4=rhvaldiff_4*pctcmhpidiff4
gen predicted_pdiff2=rhvaldiff_2*pctcmhpidiff2

* State cluster variable *

gen msa_cluster=msa
replace msa_cluster=stfips if cmhpi2000==.
sort stfips year
save psid-fertility, replace

* Read In Real Per Capita Income and Unemployment Rate Data *

use birthrate, clear
gen stfips=1 if state=="AL"
replace stfips=2 if state=="AK"
replace stfips=4 if state=="AZ"
replace stfips=5 if state=="AR"
replace stfips=6 if state=="CA"
replace stfips=8 if state=="CO"
replace stfips=9 if state=="CT"
replace stfips=10 if state=="DE"
replace stfips=11 if state=="DC"
replace stfips=12 if state=="FL"
replace stfips=13 if state=="GA"
replace stfips=15 if state=="HI"
replace stfips=16 if state=="ID"
replace stfips=17 if state=="IL"
replace stfips=18 if state=="IN"
replace stfips=19 if state=="IA"
replace stfips=20 if state=="KS"
replace stfips=21 if state=="KY"
replace stfips=22 if state=="LA"
replace stfips=23 if state=="ME"
replace stfips=24 if state=="MD"
replace stfips=25 if state=="MA"
replace stfips=26 if state=="MI"
replace stfips=27 if state=="MN"
replace stfips=28 if state=="MS"
replace stfips=29 if state=="MO"
replace stfips=30 if state=="MT"
replace stfips=31 if state=="NE"
replace stfips=32 if state=="NV"
replace stfips=33 if state=="NH"
replace stfips=34 if state=="NJ"
replace stfips=35 if state=="NM"
replace stfips=36 if state=="NY"
replace stfips=37 if state=="NC"
replace stfips=38 if state=="ND"
replace stfips=39 if state=="OH"
replace stfips=40 if state=="OK"
replace stfips=41 if state=="OR"
replace stfips=42 if state=="PA"
replace stfips=44 if state=="RI"
replace stfips=45 if state=="SC"
replace stfips=46 if state=="SD"
replace stfips=47 if state=="TN"
replace stfips=48 if state=="TX"
replace stfips=49 if state=="UT"
replace stfips=50 if state=="VT"
replace stfips=51 if state=="VA"
replace stfips=53 if state=="WA"
replace stfips=54 if state=="WV"
replace stfips=55 if state=="WI"
replace stfips=56 if state=="WY"
gen rincpercap=rpcincome*cpi
collapse (mean) rincpercap unemprate, by(stfips year)
sort stfips year
merge stfips year using psid-fertility
tab _merge
drop if _merge~=3
drop _merge
gen lrincpercap=ln(rincpercap)

* Trim Sample to Eliminate a Small Number of Outliers *

replace asample=0 if tot_fam_y_lag0==9999999 & tot_fam_y_lag0~=.
replace asample=0 if tot_fam_y_lag0<-100000 & tot_fam_y_lag0~=.
replace asample=0 if (rhvaldiff_2<-30 | rhvaldiff_2>50) & rhvaldiff_2~=.
replace asample=0 if (rhvaldiff_4<-30 | rhvaldiff_4>150) & rhvaldiff_4~=.
replace asample=0 if (rhvaldiff_2<-30 | rhvaldiff_2>50) & rhvaldiff_2~=.
replace asample=0 if (housingpricemsadiff_4<-30 | housingpricemsadiff_4>150) & housingpricemsadiff_4~=. & ownhome==0
replace asample=0 if (housingpricemsadiff_2<-30 | housingpricemsadiff_2>50) & housingpricemsadiff_2~=. & ownhome==0

* Fix Unique IDs *

gen temp="-"
egen temp2=concat(in68 temp pn68)
replace uniqueid=temp2 if year<2007
drop temp temp2
egen uniqueid2=group(uniqueid)

egen flag=tag(uniqueid2 year)
keep if flag==1

* Set up Panel *

xtset uniqueid2 year
gen birth_1 = l1.birth
gen msa_4=l4.msa
gen mover=1 if msa_4~=msa
replace mover=. if msa_4==.

* TABLE 1 *

sum birth ownhome rhomeval housingprice rhvaldiff_2 rhvaldiff_4 married rtot_fam_y_lag0 fuchildren_lag0 age1519 age2024 age2529 age3034 age3539 age4044 nohs hsdip somecoll ba edmiss unemp lrincpercap if asample==1 & ownhome==1 & age>24 & mover~=1
sum birth ownhome housingprice housingpricemsadiff_2 housingpricemsadiff_4 married rtot_fam_y_lag0 fuchildren_lag0 age1519 age2024 age2529 age3034 age3539 age4044 nohs hsdip somecoll ba edmiss unemp lrincpercap if asample==1 & ownhome==0 & age>24 & mover~=1

* FIGURE 3 *

gen temp=rhvaldiff_4/10
kdensity temp if asample==1 & ownhome==1 & age>24 & mover~=1 & rhvaldiff_4>=-29 & rhvaldiff_4<=75 & year<1990, gen(x y80s)
kdensity temp if asample==1 & ownhome==1 & age>24 & mover~=1 & rhvaldiff_4>=-29 & rhvaldiff_4<=75 & year>=1990 & year<2000, at(x) gen(y90s)
kdensity temp if asample==1 & ownhome==1 & age>24 & mover~=1 & rhvaldiff_4>=-29 & rhvaldiff_4<=75 & year>=2000, at(x) gen(y2000s)
twoway connect y80s x, msymbol(none) lpattern(dash) || connect y90s x, msymbol(none) lpattern(longdash) || connect y2000s x, msymbol(none) lpattern(solid) ||, scheme(s1mono) legend(region(lcolor(none) margin(tiny)) order(1 "1980s" 2 "1990s" 3 "2000s") ring(0) position(11) region(style(none))) xtitle("Home Price Change ($100,000)") ytitle("Density") xlabel(-3(1)7) 
graph export homepricechange.eps, replace

** TABLE 2 - Multiply by 100 to get results in table **

* State Fixed Effects - Homeowners *

xi: reg birth rhomeval married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.stfips if asample==1 & ownhome==1 & age>24 & mover~=1, cluster(msa_cluster)
xi: reg birth rhvaldiff_2 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.stfips if asample==1 & ownhome==1 & age>24 & mover~=1, cluster(msa_cluster)
xi: reg birth rhvaldiff_4 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.stfips if asample==1 & ownhome==1 & age>24 & mover~=1, cluster(msa_cluster)

* MSA Fixed Effects - Homeowners *

xi: reg birth rhomeval married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==1 & cmhpi2000~=. & age>24 & mover~=1, cluster(msa)
xi: reg birth rhvaldiff_2 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==1 & cmhpi2000~=. & age>24 & mover~=1, cluster(msa)
xi: reg birth rhvaldiff_4 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==1 & cmhpi2000~=. & age>24 & mover~=1, cluster(msa)

* State Fixed Effects - Renters  *

xi: reg birth housingprice married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.stfips if asample==1 & ownhome==0 & age>24 & mover~=1, cluster(msa_cluster)
xi: reg birth housingpricediff_2 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.stfips if asample==1 & ownhome==0 & age>24 & mover~=1, cluster(msa_cluster)
xi: reg birth  housingpricediff_4 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.stfips if asample==1 & ownhome==0 & age>24 & mover~=1, cluster(msa_cluster)

* Regressions on Renters - MSA *

xi: reg birth housingprice_msa married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==0 & cmhpi2000~=. & age>24 & mover~=1, cluster(msa)
xi: reg birth housingpricemsadiff_2 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==0 & cmhpi2000~=. & age>24 & mover~=1, cluster(msa)
xi: reg birth  housingpricemsadiff_4 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==0 & cmhpi2000~=. & age>24 & mover~=1, cluster(msa)

** TABLE 3, Columns (1) and (2) - Multiply by 100 to get results in table. See Table 3.do for the code that generates the second two columns **

* Simulated MSA Prices - Current MSA *

xi: reg birth predicted_pdiff2 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==1 & cmhpi2000~=. & age>24 & mover~=1, cluster(msa)
xi: reg birth predicted_pdiff4 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==1 & cmhpi2000~=. & age>24 & mover~=1, cluster(msa)

** Table 4 - Multiply by 100 to get results in table **

gen hvaldiff_1519=rhvaldiff_4*age1519
gen hvaldiff_2024=rhvaldiff_4*age2024
gen hvaldiff_2529=rhvaldiff_4*age2529
gen hvaldiff_3034=rhvaldiff_4*age3034
gen hvaldiff_3539=rhvaldiff_4*age3539
gen hvaldiff_4044=rhvaldiff_4*age4044

xi: reg birth hvaldiff_1519 hvaldiff_2024 hvaldiff_2529 hvaldiff_3034 hvaldiff_3539 hvaldiff_4044 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1, cluster(msa)

summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & age1519==1
summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & age2024==1
summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & age2529==1
summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & age3034==1
summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & age3539==1
summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & age4044==1

** TABLE 5 - Multiply by 100 to get results in table **

gen rhomeprice_plus4=f4.rhomeval
gen rhvaldiff_lead=rhomeprice_plus4-rhomeval
replace rhvaldiff_lead=0 if ownhome==0

xi: reg birth rhvaldiff_4 rhvaldiff_lead married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==1 & cmhpi2000~=. & age>24 & mover~=1, cluster(msa_cluster)
xi: reg birth rhvaldiff_4 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==1 & cmhpi2000~=. & age>24 & mover~=1 & rhvaldiff_lead~=., cluster(msa_cluster)

** TABLE 6 - Multiply by 100 to get results in table **

* Number of Kids *

gen hvaldiff_0kids=rhvaldiff_4 if fuchildren_lag0==0
replace hvaldiff_0kids=0 if hvaldiff_0kids==.
gen hvaldiff_1kids=rhvaldiff_4 if fuchildren_lag0==1
replace hvaldiff_1kids=0 if hvaldiff_1kids==.
gen hvaldiff_2kids=rhvaldiff_4 if fuchildren_lag0==2
replace hvaldiff_2kids=0 if hvaldiff_2kids==.
gen hvaldiff_3kids=rhvaldiff_4 if fuchildren_lag0>=3
replace hvaldiff_3kids=0 if hvaldiff_3kids==.

xi: reg birth hvaldiff_0kids hvaldiff_1kids hvaldiff_2kids hvaldiff_3kids married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==1 & cmhpi2000~=. & age>24 & mover~=1, cluster(msa_cluster)

summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & fuchildren_lag0==0
summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & fuchildren_lag0==1
summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & fuchildren_lag0==2
summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & fuchildren_lag0>=3

* By Income *

gen inc1=rtot_fam_y_lag0<5.3
gen inc2=(rtot_fam_y_lag0>=5.3 & rtot_fam_y_lag0<8)
gen inc3=(rtot_fam_y_lag0>=8 & rtot_fam_y_lag0<11.5)
gen inc4=(rtot_fam_y_lag0>=11.5)

gen hvaldiff_inc1=rhvaldiff_4*inc1
gen hvaldiff_inc2=rhvaldiff_4*inc2
gen hvaldiff_inc3=rhvaldiff_4*inc3
gen hvaldiff_inc4=rhvaldiff_4*inc4

xi: reg birth hvaldiff_inc1 hvaldiff_inc2 hvaldiff_inc3 hvaldiff_inc4 inc2-inc4 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==1 & cmhpi2000~=. & age>24 & mover~=1, cluster(msa_cluster)

summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & inc1==1
summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & inc2==1
summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & inc3==1
summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & inc4==1

* By Decade *

replace decade_80s=0 if decade_80s==.
replace decade_90s=0 if decade_90s==.
replace decade_2000s=0 if decade_2000s==.

capture drop rhvaldiff_2_80s
capture drop rhvaldiff_4_80s
gen rhvaldiff_2_80s=rhvaldiff_2*decade_80s
gen rhvaldiff_2_90s=rhvaldiff_2*decade_90s
gen rhvaldiff_2_2000s=rhvaldiff_2*decade_2000s
gen rhvaldiff_4_80s=rhvaldiff_4*decade_80s
gen rhvaldiff_4_90s=rhvaldiff_4*decade_90s
gen rhvaldiff_4_2000s=rhvaldiff_4*decade_2000s

xi: reg birth rhvaldiff_4_80s rhvaldiff_4_90s rhvaldiff_4_2000s married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss unemp lrincpercap i.year i.msa if asample==1 & ownhome==1 & cmhpi2000~=. & age>24 & mover~=1, cluster(msa_cluster)

summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & decade_80s==1
summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & decade_90s==1
summ birth if asample==1 & ownhome==1 & cmhpi2000~=. & mover~=1 & decade_2000s==1

* APPENDIX TABLE A-1 - Multiply by 100 to get results in table *

xi: reg birth rhomeval married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss i.stfips*i.year if asample==1 & ownhome==1 & age>24 & mover~=1, cluster(msa_cluster)
xi: reg birth  rhvaldiff_2 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss i.stfips*i.year if asample==1 & ownhome==1 & age>24 & mover~=1, cluster(msa_cluster)
xi: reg birth  rhvaldiff_4 married rtot_fam_y_lag0 fuchildren_lag0 age2024 age2529 age3034 age3539 age4044 hsdip somecoll ba edmiss i.stfips*i.year if asample==1 & ownhome==1 & age>24 & mover~=1, cluster(msa_cluster)
